package jtacck.labmedicine;

import com.google.android.maps.Overlay;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.RectF;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Projection;

/**
 * @deprecated
 * An overlay used to draw the route.
 * 
 * @see com.google.android.maps.Overlay
 * 
 * @author Andrewlo
 * 
 */
public class MyOverLay extends Overlay {

    /**
     * Location of first of series of points
     */
    private GeoPoint gp1;

    /**
     * Location of the second points
     */
    private GeoPoint gp2;

    /**
     * Radius of the route.
     */
    private int mRadius = 6;

    /**
     * Default mode of the circle.
     */
    private int mode = 0;

    /**
     * Color of the path.
     */
    private int defaultColor;
    @SuppressWarnings("unused")
    private String text = "";
    @SuppressWarnings("unused")
    private Bitmap img = null;

    /**
     * Creates a new overlay with a beginning and ending geopoint with a mode.
     * 
     * @param gp1
     *            - the first point
     * @param gp2
     *            - the second point
     * @param mode
     *            - the mode of the route
     */
    public MyOverLay(GeoPoint gp1, GeoPoint gp2, int mode) {
        this(gp1, gp2, mode, 999);
    }

    /**
     * Constructs a new overlay with a given end, beginning, mode, and default
     * color.
     * 
     * @param gp1
     *            - first point of the current path to be drawn
     * @param gp2
     *            - second point of the path to be drawn
     * @param mode
     *            - which part of the route
     * @param defaultColor
     *            - the color of the route
     */
    public MyOverLay(GeoPoint gp1, GeoPoint gp2, int mode, int defaultColor) {
        this.gp1 = gp1;
        this.gp2 = gp2;
        this.mode = mode;
        this.defaultColor = defaultColor;
    }

    /**
     * Sets the text for the route.
     * 
     * @param text
     *            - the text to used
     */
    public void setText(String text) {
        this.text = text;
    }

    /**
     * Sets a bitmap to be used on the route
     * 
     * @param bitmap
     *            - the bitmap to be used
     */
    public void setBitmap(Bitmap bitmap) {
        this.img = bitmap;
    }

    /**
     * Retrieves the current mode.
     * 
     * @return The int representing the mode.
     */
    public int getMode() {
        return mode;
    }

    /* (non-Javadoc)
     * @see com.google.android.maps.Overlay#draw(android.graphics.Canvas, com.google.android.maps.MapView, boolean, long)
     * 
     * Overriden draw method which calcualtes the points to be drawn.
     */
    @Override
    public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
            long when) {
        Projection projection = mapView.getProjection();
        if (shadow == false) {
            Paint paint = new Paint();
            paint.setAntiAlias(true);
            Point point = new Point();
            projection.toPixels(gp1, point);
            // mode=1 start
            if (mode == 1) {
                if (defaultColor == 999)
                    paint.setColor(Color.BLUE);
                else
                    paint.setColor(defaultColor);
                RectF oval = new RectF(point.x - mRadius, point.y - mRadius,
                        point.x + mRadius, point.y + mRadius);
                // start point
                canvas.drawOval(oval, paint);
            }
            // mode=2 path
            else if (mode == 2) {
                if (defaultColor == 999)
                    paint.setColor(Color.RED);
                else
                    paint.setColor(defaultColor);
                Point point2 = new Point();
                projection.toPixels(gp2, point2);
                paint.setStrokeWidth(5);
                paint.setAlpha(120);
                
                //The actual path
                canvas.drawLine(point.x, point.y, point2.x, point2.y, paint);
            }
            /* mode=3 end */
            else if (mode == 3) {
                /* the last path */

                if (defaultColor == 999)
                    paint.setColor(Color.GREEN);
                else
                    paint.setColor(defaultColor);
                Point point2 = new Point();
                projection.toPixels(gp2, point2);
                paint.setStrokeWidth(5);
                paint.setAlpha(120);
                canvas.drawLine(point.x, point.y, point2.x, point2.y, paint);
                RectF oval = new RectF(point2.x - mRadius, point2.y - mRadius,
                        point2.x + mRadius, point2.y + mRadius);
                /* end point */
                paint.setAlpha(255);
                canvas.drawOval(oval, paint);
            }
        }
        return super.draw(canvas, mapView, shadow, when);
    }

}
